package com.kgc.dubbo.controller;

import com.kgc.dubbo.utils.compoent.ActiveMQutil;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.JMSException;

/**
 * ActiveMQ的测试的控制器
 */
@RestController
@RequestMapping("/activemq")
public class ActiveMQController {
    @Autowired
    private ActiveMQutil activeMQutil;
    @GetMapping(value = "/send")
    public String sendMessageToActiveMQ(){
        activeMQutil.sendMessage("test","hello activemq");
        return "success";
    }
    @JmsListener(destination = "test")
    public void dealGetMessage(Object message) throws JMSException {
        ActiveMQTextMessage activeMQTextMessage = (ActiveMQTextMessage)message;
        System.out.println(activeMQTextMessage.getText());
    }
}
